<?php   // $Id: client_update.php 89 2007-12-02 23:47:31Z pcoustillas $ ?>
<?php   
/*Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx
Modification : Pierre Coustillas*/

require_once(dirname(__FILE__) ."/verif_client.php");

require_once("../include/config/common.php");
require_once("../include/config/var.php");
$lang = $_SESSION['lang'];
require_once(dirname(__FILE__) ."/../include/utils.php");
require_once("../include/language/$lang.php");


$login=isset($_POST['login'])?$_POST['login']:"";
$pass=isset($_POST['pass'])?$_POST['pass']:"";
$pass_new=isset($_POST['pass_new'])?$_POST['pass_new']:"";
$pass_new2=isset($_POST['pass_new2'])?$_POST['pass_new2']:"";
$num_client=isset($_POST['num_client'])?$_POST['num_client']:"";

$erreur=0 ; //drapeau permettant de savoir si une erreur à été détecte.

if($pass=='' || $pass_new=='' || $pass_new2=='' || $login=='' )
{
    $msg=$lang_err_chan_mdp;
	$erreur=1;
}
$sql2 = "SELECT * FROM " . $tblpref ."client WHERE num_client= $num_client";
$req = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
$data = mysql_fetch_array($req);
$ancienpass= $data['pass'];
if($ancienpass != md5($pass) )
{
	$msg=$lang_err_ancien_mdp;
	$erreur=1;
}
if($pass_new != $pass_new2)
{
    $msg=get_lang("Les deux mots de passe saisie ne sont pas identique");
	$erreur=1;
}


if ($erreur==0) 
{
	
	$pass = md5($pass_new);
	$sql2 = "UPDATE " . $tblpref ."client SET pass='".$pass."' WHERE num_client = $num_client";
	mysql_query($sql2) OR die("<p>Erreur Mysql<br/>$sql2<br/>".mysql_error()."</p>");
	
	$sql2 = "SELECT * FROM " . $tblpref ."client WHERE num_client= $num_client";
	$req = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
	while($data = mysql_fetch_array($req))
		{
		$to = $data['mail'];
		}
	$msg=get_lang("Votre mot de passe à été mis à jour");
	
	/*
	$from = "$mail" ;
	$subject = "$lang_dif_mail_mdp" ;
	$message =  "Cher client<br>$lang_mdp_jour<br><b>Login: $login $lang_mai_cr_pa $pass_new2</b><br>$lang_mai_cre_enc<br> "; 
	$header = 'From: '.$from."\n"
	.'MIME-Version: 1.0'."\n"
	.'Content-Type: text/html; charset= UTF-8'."\n"
	.'Content-Transfer-Encoding: 7bit'."\n\n";
	
	mail($to,$subject,$message,$header);
	*/
}

header("Location: client.php?msg=" . $msg); // On redirige vers le formulaire d'identification

?> 
